#define DEBUG
#include <cstdio>
#include <cstring>
#define maxk 200
#define ms 998244353

using namespace std;

class Matrix {
public:
  int n, m, a[maxk+1][maxk+1];
};

inline void mul(Matrix *a, Matrix *x, Matrix *y, int mods) {
  a->n = x->n, a->m = y->m;
  for (int i=0; i<a->n; i++) {
    for (int j=0; j<a->m; j++) {
      a->a[i][j] = 0;
      for (int k=0; k<x->m; k++) {
	a->a[i][j] = (long long)(a->a[i][j]+(long long)x->a[i][k]*y->a[k][j])%mods;
      }
    }
  }
}

void one(Matrix *a, int x) {
  a->n = a->m = x;
  for (int i=0; i<x; i++) {
    a->a[i][i] = 1;
  }
}

void qpower(Matrix *a, int n, int mods) {
  static Matrix s[2], t[2];
  one(s, a->n);
  t[0] = *a;
  int i=0, j=0;
  for (; n>1; n/=2) {
    if (n%2) {
      j=(j+1)%2;
      mul(s+j, t+i, s+((j+1)%2), mods);
    }
    i=(i+1)%2;
    mul(t+i, t+((i+1)%2), t+((i+1)%2), mods);
  }
  mul(a, t+i, s+j, mods);
}

int qpower(int a, int n, int mods) {
  if (n==0) {
    return 1;
  }
  int s=1;
  for (; n>1; n/=2) {
    if (n%2) {
      s = (long long)s*a%mods;
    }
    a = (long long)a*a%mods;
  }
 return (long long)s*a%mods;
}

void initMatrix(Matrix *a, int k, int *b) {
  a->n = a->m = k;
  for (int i=1; i<=k; i++) {
    a->a[i-1][0] = b[i];
    if (i<k) {
      a->a[i-1][i] = 1;
    }
  }
}

int solve(int n, int k, int *b, int *f) {
  if (n<=k) {
    return f[n];
  }
  Matrix tpl, temp[2];
  initMatrix(&tpl, k, b);
  qpower(&tpl, n-k, ms-1);
  int ans=1;
  memset(temp, 0, sizeof(temp[0]));
  temp[0].n = 1, temp[0].m = k;
  for (int i=0; i<k; i++) {
    temp[0].a[0][i] = 1;
  }
  mul(temp+1, temp, &tpl, ms-1);
  for (int i=0; i<k; i++) {
    ans = (long long)ans*qpower(f[k-i], temp[1].a[0][0], ms)%ms;
  }
  return ans;
}

int main() {
  freopen("seq.in", "r", stdin);
  freopen("seq.out", "w", stdout);

  static int b[maxk+1], f[maxk+1];
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i=1; i<=k; i++) {
    scanf("%d", b+i);
  }
  for (int i=1; i<=k; i++) {
    scanf("%d", f+i);
  }

  printf("%d\n", solve(n, k, b, f));
    
  fclose(stdin);
  fclose(stdout);
  return 0;
}
